import request from "@/utils/request";

const NOTICE_BASE_URL = "/api/v1/notices";

const NoticeAPI = {
  getPage(queryParams?: NoticePageQuery) {
    return request<any, PageResult<NoticePageVO[]>>({
      url: `${NOTICE_BASE_URL}/page`,
      method: "get",
      params: queryParams,
    });
  },

  getFormData(id: number) {
    return request<any, NoticeForm>({
      url: `${NOTICE_BASE_URL}/${id}/form`,
      method: "get",
    });
  },

  add(data: NoticeForm) {
    return request({
      url: `${NOTICE_BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  update(id: number, data: NoticeForm) {
    return request({
      url: `${NOTICE_BASE_URL}/${id}`,
      method: "put",
      data: data,
    });
  },

  deleteByIds(ids: string) {
    return request({
      url: `${NOTICE_BASE_URL}/${ids}`,
      method: "delete",
    });
  },

  publish(id: number) {
    return request({
      url: `${NOTICE_BASE_URL}/${id}/publish`,
      method: "put",
    });
  },

  revoke(id: number) {
    return request({
      url: `${NOTICE_BASE_URL}/${id}/revoke`,
      method: "put",
    });
  },

  getDetail(id: string) {
    return request<any, NoticeDetailVO>({
      url: `${NOTICE_BASE_URL}/${id}/detail`,
      method: "get",
    });
  },

  readAll() {
    return request({
      url: `${NOTICE_BASE_URL}/read-all`,
      method: "put",
    });
  },

  getMyNoticePage(queryParams?: NoticePageQuery) {
    return request<any, PageResult<NoticePageVO[]>>({
      url: `${NOTICE_BASE_URL}/my-page`,
      method: "get",
      params: queryParams,
    });
  },
};

export default NoticeAPI;

export interface NoticePageQuery extends PageQuery {
  title?: string;
  publishStatus?: number;
  isRead?: number;
}

export interface NoticeForm {
  id?: number;
  title?: string;
  content?: string;
  type?: number;
  level?: string;
  targetType?: number;
  targetUserIds?: string;
}

export interface NoticePageVO {
  id: string;
  title?: string;
  content?: string;
  type?: number;
  publisherId?: bigint;
  priority?: number;
  targetType?: number;
  publishStatus?: number;
  publishTime?: Date;
  revokeTime?: Date;
}

export interface NoticeDetailVO {
  id?: string;

  title?: string;

  content?: string;

  type?: number;

  publisherName?: string;

  level?: string;

  publishTime?: Date;

  publishStatus?: number;
}
